﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;

namespace WhittleList.Bll
{
    public interface IWhittleListDataContext
    {

        IEnumerable<T> GetInserts<T>();
        IEnumerable<T> GetUpdates<T>();
        void SubmitChanges();

        IQueryable<User> Users { get; }
        void Insert(User item);

        IQueryable<Site> Sites { get; }
        void Insert(Site item);

        IQueryable<Project> Projects { get; }
        void Insert(Project item);

        IQueryable<UserProjectRole> UserProjectRoles { get; }
        void Insert(UserProjectRole item);

        IQueryable<Section> Sections { get; }
        void Insert(Section item);

        IQueryable<Item> Items { get; }
        void Insert(Item item);
    }

    public partial class WhittleListDataContext : IWhittleListDataContext
    {
        #region IWhittleListDataContext Members

        IEnumerable<T> IWhittleListDataContext.GetInserts<T>()
        {
            return this.GetChangeSet().Inserts.OfType<T>();
        }

        IEnumerable<T> IWhittleListDataContext.GetUpdates<T>()
        {
            return this.GetChangeSet().Updates.OfType<T>();
        }

        void IWhittleListDataContext.SubmitChanges()
        {
            this.SubmitChanges();
        }

        IQueryable<User> IWhittleListDataContext.Users
        {
            get { return this.Users; }
        }

        void IWhittleListDataContext.Insert(User user)
        {
            this.Users.InsertOnSubmit(user);
        }


        IQueryable<Site> IWhittleListDataContext.Sites
        {
            get { return this.Sites; }
        }

        void IWhittleListDataContext.Insert(Site site)
        {
            this.Sites.InsertOnSubmit(site);
        }

        IQueryable<Project> IWhittleListDataContext.Projects
        {
            get { return this.Projects; }
        }

        void IWhittleListDataContext.Insert(Project project)
        {
            this.Projects.InsertOnSubmit(project);
        }

        IQueryable<UserProjectRole> IWhittleListDataContext.UserProjectRoles
        {
            get { return this.UserProjectRoles; }
        }

        void IWhittleListDataContext.Insert(UserProjectRole userProjectRole)
        {
            this.UserProjectRoles.InsertOnSubmit(userProjectRole);
        }

        IQueryable<Section> IWhittleListDataContext.Sections
        {
            get { return this.Sections; }
        }

        void IWhittleListDataContext.Insert(Section item)
        {
            this.Sections.InsertOnSubmit(item);
        }

        IQueryable<Item> IWhittleListDataContext.Items
        {
            get { return this.Items; }
        }

        void IWhittleListDataContext.Insert(Item item)
        {
            this.Items.InsertOnSubmit(item);
        }
        #endregion
    }
}
